<script>
  export default {
    globalData: {
      baseUrl: "http://101.200.86.62:8081"
    },
    onLaunch: function() {
      console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
      console.log('App Launch')
      uni.login({
        success: res => {
          let appid = "wx8a3f95e1a3593dbd"
          let secret = "09f1d4a7563ed422f595212afdfffa94"
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          let tmp = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret +
            '&js_code=' + res.code
          uni.request({
            url: tmp,
            method: 'GET',
            success: res => {
              uni.request({
                url: getApp().globalData.baseUrl + '/logIn',
                // "http://101.200.86.62:8081"
                method: 'POST',
                data: {
                  openId: res.data.openid
                },
                header: {
                  "Content-Type": "application/x-www-form-urlencoded"
                },
                // 请求成功返回userId，存到全局数据中
                success(res) {
                  uni.setStorageSync("userId", res.data)

                }
              })
            }
          })
        }
      })
    },
    onShow: function() {
      console.log('App Show')
    },
    onHide: function() {
      console.log('App Hide')
    }
  }
</script>

<style lang="scss">
  /*每个页面公共css */
  @import '@/uni_modules/uni-scss/index.scss';
  /* #ifndef APP-NVUE */
  @import '@/static/customicons.css';

  // 设置整个项目的背景色
  page {
    background-color: #f5f5f5;
  }

  /* #endif */
  .example-info {
    font-size: 14px;
    color: #333;
    padding: 10px;
  }
</style>